import * as echarts from 'echarts';

import chinaMapData from '../data/china.json';
echarts.registerMap('china', chinaMapData);

export default function (el: HTMLElement) {
  const echartInstance = echarts.init(el, 'dark', {
    renderer: 'svg'
  });
  const setOptions = (options: echarts.EChartsOption) => {
    echartInstance.setOption(options);
  };
  const updateEchartSize = () => {
    echartInstance.resize();
  };
  window.addEventListener('resize', () => {
    echartInstance.resize();
  });
  return {
    setOptions,
    updateEchartSize,
    echartInstance
  };
}
